# 通过 OCR 识别微信好友的昵称、个性签名、备注等文本，结合规则解析姓氏和性别：
import requests
import base64

def aliyun_ocr(image_path):
    # 读取图片并Base64编码
    with open(image_path, "rb") as f:
        img_base64 = base64.b64encode(f.read()).decode()
    
    # 阿里云OCR接口参数（通用文字识别）
    url = "https://ocr.cn-hangzhou.aliyuncs.com"
    headers = {"Authorization": "APPCODE your_appcode"}  # 替换为实际APPCODE
    data = {
        "image": img_base64,
        "configure": {"format": "json", "charInfo": True}
    }
    response = requests.post(url, json=data, headers=headers)
    return response.json()

# 示例：截取好友资料页截图并调用OCR
driver.get_screenshot_as_file("friend_profile.png")  # Appium截图
ocr_result = aliyun_ocr("friend_profile.png")